/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package br.com.ekaaty.dao;

import java.util.List;
import br.com.ekaaty.bean.Evento;
import java.util.Date;
import org.hibernate.Criteria;
import org.hibernate.criterion.Restrictions;
/**
 *
 * @author otavio
 */
public class EventoDao extends  CRUDGeneric<Evento> {

    @Override
    public Evento recuperar(int cod) {
       OpenSession();
       Evento evento=(Evento)session.get(Evento.class, cod);
       CloseSession();
       return evento;
    }

    @Override
    public List<Evento> listar() {
   OpenSession();
       Criteria criteria= session.createCriteria(Evento.class);
        List<Evento> eventos = criteria.list();
        CloseSession();
        return eventos;
    }

    @Override
    public boolean ehUnico(Evento bean) {
       OpenSession();
        Criteria criteria = session.createCriteria(Evento.class);
        criteria.add(Restrictions.eq("nome", bean.getNome()));
        List<Evento> eventos = criteria.list();
        int total=eventos.size();
        CloseSession();
        if (total == 0) {
            return true;
        } else {
            return false;
        }
    }

      public List listarAtuais() {
        OpenSession();
        String sql = "select e from Evento e where e.data >=:date";
        List<Evento> eventos = session.createQuery(sql).setDate("date", new Date()).list();
        CloseSession();
        return eventos;
    }

  
}
